md-editor-rt
Version:
Markdown editor for react, developed in jsx and typescript, dark theme、beautify content by prettier、render articles directly、paste or clip the picture and upload it...
2 lines (1 loc) • 4.35 kB
JavaScript
"use strict";const n=require("react/jsx-runtime"),i=require("react"),P=require("react-dom"),o=require("./config.cjs"),y=require("./context.cjs"),j=require("./index2.cjs"),R=require("./dom.cjs"),e=require("lucide-react"),q=t=>n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:`lucide lucide-github-icon ${t.className}`,children:[n.jsx("path",{d:"M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"}),n.jsx("path",{d:"M9 18c-4.51 2-5-2-7-2"})]}),E={bold:e.Bold,underline:e.Underline,italic:e.Italic,"strike-through":e.Strikethrough,title:e.Heading,sub:e.Subscript,sup:e.Superscript,quote:e.Quote,"unordered-list":e.List,"ordered-list":e.ListOrdered,task:e.ListTodo,"code-row":e.Code,code:e.SquareCode,link:e.Link,image:e.Image,table:e.Table,revoke:e.Reply,next:e.Forward,save:e.Save,prettier:e.SquareCode,minimize:e.Minimize2,maximize:e.Maximize2,"fullscreen-exit":e.Shrink,fullscreen:e.Expand,"preview-only":e.View,preview:e.Eye,"preview-html":e.CodeXml,catalog:e.ListTree,github:q,mermaid:e.ChartArea,formula:e.SquareSigma,close:e.X,delete:e.Trash2,upload:e.Upload},F=t=>i.createElement(E[t.name],{className:`${o.prefix}-icon`}),L=i.memo(F),S=t=>{const{customIcon:u}=i.useContext(y.EditorContext),r=u[t.name];if(typeof r=="object"){const c=r.component;return typeof c=="function"?n.jsx(c,{...r.props}):n.jsx("span",{dangerouslySetInnerHTML:{__html:r.component}})}return n.jsx(L,{name:t.name})},B=`${o.prefix}-modal-container`,H=t=>{const{theme:u,rootRef:r}=i.useContext(y.EditorContext),{onClose:c=()=>{},onAdjust:C=()=>{},style:b={},showMask:w=!0}=t,[m,k]=i.useState(t.visible),[z,v]=i.useState([`${o.prefix}-modal`]),f=i.useRef(null),I=i.useRef(null),a=i.useRef(null),M=i.useRef(null),[x,d]=i.useState({maskStyle:{zIndex:-1},modalStyle:{zIndex:-1},initPos:{insetInlineStart:"0px",insetBlockStart:"0px"},historyPos:{insetInlineStart:"0px",insetBlockStart:"0px"}}),N=i.useMemo(()=>t.isFullscreen?{width:"100%",height:"100%"}:{width:t.width,height:t.height},[t.height,t.isFullscreen,t.width]);return i.useEffect(()=>{const s=r?.current?.getRootNode();return a.current=s instanceof Document?document.body:s,()=>{a.current=null}},[r]),i.useEffect(()=>{let s=()=>{};return!t.isFullscreen&&t.visible&&(s=R.keyMove(I.current,(l,h)=>{d(g=>({...g,initPos:{insetInlineStart:l+"px",insetBlockStart:h+"px"}}))})),s},[t.isFullscreen,t.visible]),i.useEffect(()=>{if(m){const s=f.current.offsetWidth/2,l=f.current.offsetHeight/2,h=document.documentElement.clientWidth/2,g=document.documentElement.clientHeight/2;d($=>({...$,maskStyle:{zIndex:o.globalConfig.editorConfig.zIndex+j.getZIndexIncrement()},modalStyle:{zIndex:o.globalConfig.editorConfig.zIndex+j.getZIndexIncrement()},initPos:{insetInlineStart:h-s+"px",insetBlockStart:g-l+"px"}}))}},[m]),i.useEffect(()=>{const s=t.visible;s?(v(()=>[`${o.prefix}-modal`,"zoom-in"]),k(s)):(v(()=>[`${o.prefix}-modal`,"zoom-out"]),setTimeout(()=>{k(s)},150))},[t.visible]),n.jsx(n.Fragment,{children:a.current&&P.createPortal(n.jsx("div",{ref:M,className:B,"data-theme":u,children:n.jsxs("div",{className:t.className,style:{...b,display:m?"block":"none"},children:[w&&n.jsx("div",{className:`${o.prefix}-modal-mask`,style:x.maskStyle,onClick:c}),n.jsxs("div",{className:z.join(" "),style:{...x.modalStyle,...x.initPos,...N},ref:f,children:[n.jsx("div",{className:`${o.prefix}-modal-header`,ref:I,children:t.title||""}),n.jsxs("div",{className:`${o.prefix}-modal-func`,children:[t.showAdjust&&n.jsx("div",{className:`${o.prefix}-modal-adjust`,onClick:s=>{s.stopPropagation(),t.isFullscreen?d(l=>({...l,initPos:l.historyPos})):d(l=>({...l,historyPos:l.initPos,initPos:{insetInlineStart:"0",insetBlockStart:"0"}})),C instanceof Function&&C(!t.isFullscreen)},children:n.jsx(S,{name:t.isFullscreen?"minimize":"maximize"})}),n.jsx("div",{className:`${o.prefix}-modal-close`,onClick:s=>{s.stopPropagation(),t.onClose&&t.onClose()},children:n.jsx(S,{name:"close"})})]}),n.jsx("div",{className:`${o.prefix}-modal-body`,children:t.children})]})]})}),a.current)})},T=i.memo(H);exports.IconIns=S;exports.Modal=T;