All checks were successful
Deploy Docs to Synology / deploy (push) Successful in 3s
8 lines
7.8 KiB
JavaScript
8 lines
7.8 KiB
JavaScript
import{$ as p,isFunc as E,h as e}from"./sigpro.js";var k=(a)=>typeof a==="function"?a():a;var w=(...a)=>a.filter(Boolean).join(" ").trim();var H=(a)=>{let{value:x,class:L}=a,l=null,r=null,i=p(!1),u=p(""),y=p(0),m=p(0),d=p(!1),C=["\uD83D\uDE00","\uD83D\uDE0A","\uD83D\uDE09","\uD83E\uDDD0","\uD83D\uDE2E","\uD83E\uDD14","\uD83D\uDE05","\uD83D\uDE02","\uD83D\uDE0D","\uD83D\uDE18","\uD83E\uDD70","\uD83D\uDC4D","\uD83D\uDC4E","\uD83D\uDC4C","\uD83E\uDD1D","\uD83E\uDD1E","\uD83D\uDC4B","\uD83D\uDC4F","\uD83D\uDE4C","\uD83D\uDE4F","\uD83D\uDCAA","☝️","\uD83D\uDC47","\uD83D\uDC48","\uD83D\uDC49","\uD83D\uDD95","✅","⚠️","\uD83D\uDE80","\uD83D\uDCE2","✉️","❤️"],g=()=>{let t=window.getSelection();if(t.getRangeAt&&t.rangeCount)r=t.getRangeAt(0)},T=()=>{if(r){let t=window.getSelection();t.removeAllRanges(),t.addRange(r)}},h=()=>{if(m(m()+1),l)y(l.innerText.length)},f=()=>{if(!l)return;let t=l.innerHTML;if(E(x))x(t);else a.onchange?.(t);h()},n=(t,o=null)=>{if(!l)return;if(l.focus(),r)T();document.execCommand(t,!1,o),r=null,f()},$=(t)=>{let o=document.createElement("div");o.style="position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.9);z-index:9999;display:flex;align-items:center;justify-content:center;cursor:zoom-out;";let s=document.createElement("img");s.src=t,s.style="max-width:95%;max-height:95%;box-shadow:0 0 30px rgba(0,0,0,0.5);border-radius:4px;",o.onclick=()=>document.body.removeChild(o),o.appendChild(s),document.body.appendChild(o)},v=(t)=>{if(!t)return;let o=new FileReader;o.onload=(s)=>{if(t.type.startsWith("image/")){let c=`<div style="display:inline-block; resize:both; overflow:hidden; vertical-align:bottom; line-height:0; width:200px; height:auto; border:1px dashed #ccc; padding:2px; cursor:pointer;" class="resizable-img-container"><img src="${s.target.result}" style="width:100%; height:100%; object-fit:contain; pointer-events:none;"></div> `;n("insertHTML",c)}else{let c=`<a href="${s.target.result}" download="${t.name}" contenteditable="false" style="display:inline-flex; align-items:center; gap:5px; padding:4px 8px; border:1px solid #ccc; border-radius:4px; background:#f9f9f9; text-decoration:none; color:#333; font-size:12px; margin:2px; cursor:pointer;"><span class="icon-[lucide--paperclip] w-3 h-3"></span>${t.name}</a> `;n("insertHTML",c)}},o.readAsDataURL(t)},b=(t,o=null)=>{if(m(),!l||i())return!1;try{if(t==="formatBlock"){let s=window.getSelection().getRangeAt(0).commonAncestorContainer;while(s&&s!==l){if(s.nodeType===1&&s.tagName===o)return!0;s=s.parentNode}return!1}return document.queryCommandState(t)}catch(s){return!1}},S=e("div",{class:"flex flex-wrap items-center gap-1 p-2 border-b border-base-300 bg-base-200 sticky top-0 z-20"},[e("div",{class:"flex flex-wrap gap-1 flex-1 items-center"},[e("button",{type:"button",class:()=>`btn btn-ghost btn-xs ${b("bold")?"btn-active bg-primary/20":""}`,onclick:()=>n("bold")},e("span",{class:"icon-[lucide--bold]"})),e("button",{type:"button",class:()=>`btn btn-ghost btn-xs ${b("italic")?"btn-active bg-primary/20":""}`,onclick:()=>n("italic")},e("span",{class:"icon-[lucide--italic]"})),e("button",{type:"button",class:()=>`btn btn-ghost btn-xs ${b("underline")?"btn-active bg-primary/20":""}`,onclick:()=>n("underline")},e("span",{class:"icon-[lucide--underline]"})),e("input",{type:"color",class:"w-5 h-5 p-0 border-0 bg-transparent cursor-pointer",oninput:(t)=>n("foreColor",t.target.value)}),e("span",{class:"w-px h-5 bg-base-300 mx-1"}),e("button",{type:"button",class:"btn btn-ghost btn-xs",onclick:()=>n("justifyLeft")},e("span",{class:"icon-[lucide--align-left]"})),e("button",{type:"button",class:"btn btn-ghost btn-xs",onclick:()=>n("justifyCenter")},e("span",{class:"icon-[lucide--align-center]"})),e("button",{type:"button",class:"btn btn-ghost btn-xs",onclick:()=>n("justifyRight")},e("span",{class:"icon-[lucide--align-right]"})),e("span",{class:"w-px h-5 bg-base-300 mx-1"}),e("button",{type:"button",class:"btn btn-ghost btn-xs",onclick:()=>n("insertUnorderedList")},e("span",{class:"icon-[lucide--list]"})),e("button",{type:"button",class:"btn btn-ghost btn-xs",onclick:()=>n("insertOrderedList")},e("span",{class:"icon-[lucide--list-ordered]"})),e("button",{type:"button",class:"btn btn-ghost btn-xs",onclick:()=>n("outdent")},e("span",{class:"icon-[lucide--indent-decrease]"})),e("button",{type:"button",class:"btn btn-ghost btn-xs",onclick:()=>n("indent")},e("span",{class:"icon-[lucide--indent-increase]"})),e("button",{type:"button",class:()=>`btn btn-ghost btn-xs ${b("formatBlock","BLOCKQUOTE")?"btn-active":""}`,onclick:()=>n("formatBlock",b("formatBlock","BLOCKQUOTE")?"P":"BLOCKQUOTE")},e("span",{class:"icon-[lucide--quote]"})),e("span",{class:"w-px h-5 bg-base-300 mx-1"}),e("button",{type:"button",class:"btn btn-ghost btn-xs",onclick:()=>{let t=window.prompt("URL:");if(t)n("createLink",t)}},e("span",{class:"icon-[lucide--link]"})),e("button",{type:"button",class:"btn btn-ghost btn-xs",onclick:()=>{let t=document.createElement("input");t.type="file",t.onchange=(o)=>v(o.target.files[0]),t.click()}},e("span",{class:"icon-[lucide--paperclip]"})),e("div",{class:"relative"},[e("button",{type:"button",class:"btn btn-ghost btn-xs",onclick:(t)=>{t.stopPropagation(),g(),d(!d())}},e("span",{class:"icon-[lucide--smile]"})),e("div",{class:"absolute top-full left-0 mt-1 p-2 bg-base-100 border border-base-300 shadow-xl rounded-box w-52 z-50 flex flex-wrap gap-1",style:()=>d()?"display:flex":"display:none"},C.map((t)=>e("span",{class:"cursor-pointer hover:bg-base-200 p-1 rounded text-lg",onclick:(o)=>{o.stopPropagation(),n("insertText",t),d(!1)}},t)))]),e("span",{class:"w-px h-5 bg-base-300 mx-1"}),e("button",{type:"button",class:"btn btn-ghost btn-xs",onclick:()=>n("undo")},e("span",{class:"icon-[lucide--undo-2]"})),e("button",{type:"button",class:"btn btn-ghost btn-xs",onclick:()=>n("redo")},e("span",{class:"icon-[lucide--redo-2]"}))]),e("button",{type:"button",class:()=>`btn btn-ghost btn-xs ${i()?"btn-active":""}`,onclick:()=>{if(!i())u(l?.innerHTML||"");else if(l)l.innerHTML=u(),f();i(!i())}},e("span",{class:"icon-[lucide--code-2]"}))]);if(typeof document<"u"&&!document.getElementById("editor-styles")){let t=document.createElement("style");t.id="editor-styles",t.textContent=`
|
|
[contenteditable="true"] div,
|
|
[contenteditable="true"] p {
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
`,document.head.appendChild(t)}return e("div",{class:w("border border-base-300 rounded-box bg-base-100 overflow-hidden shadow-sm flex flex-col",L)},[S,e("div",{class:"relative flex-1 flex flex-col",onclick:()=>d(!1)},[e("div",{ref:(t)=>{if(!l&&t)l=t,t.innerHTML=k(x)||"",document.execCommand("defaultParagraphSeparator",!1,"br"),t.addEventListener("click",(o)=>{let s=o.target.closest(".resizable-img-container");if(s){let c=s.querySelector("img");if(c)$(c.src)}})},style:()=>`min-height:22rem;${i()?"display:none":""}`,class:"p-4 outline-none text-base-content leading-relaxed [&>div]:m-0 [&>p]:m-0 [&>div]:min-h-[1em] [&_.resizable-img-container]:hover:border-primary [&_blockquote]:border-l-4 [&_blockquote]:border-base-300 [&_blockquote]:pl-4 [&_blockquote]:italic [&_ul]:list-disc [&_ul]:pl-8 [&_ol]:list-decimal [&_ol]:pl-8",contenteditable:"true",oninput:f,onkeydown:(t)=>{if(t.key==="Tab")t.preventDefault(),n("indent")},onkeyup:()=>{h(),g()},onclick:(t)=>{h(),g(),t.stopPropagation()},onmouseup:()=>{f(),g()},onpaste:(t)=>{t.preventDefault();let o=t.clipboardData.getData("text/plain");n("insertText",o)},ondragover:(t)=>t.preventDefault(),ondrop:(t)=>{t.preventDefault(),v(t.dataTransfer.files[0])}}),e("textarea",{class:"w-full flex-1 min-h-[22rem] p-4 outline-none font-mono text-sm bg-base-200 border-0",style:()=>i()?"":"display:none",value:u,oninput:(t)=>{if(u(t.target.value),l)l.innerHTML=t.target.value;a.onchange?.(t.target.value)}})]),e("div",{class:"px-3 py-1 border-t border-base-300 bg-base-100/50 text-[10px] text-right text-base-content/60 italic"},[e("span",()=>`${y()}`)])])};export{H as Editor};
|