UNPKG

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.23 kB
"use strict";const n=require("react/jsx-runtime"),o=require("react"),R=require("react-dom"),s=require("./config.cjs"),q=require("./dom.cjs"),S=require("./context.cjs"),b=require("./index3.cjs"),e=require("lucide-react"),$=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:$,mermaid:e.ChartArea,formula:e.SquareSigma,close:e.X,delete:e.Trash2,upload:e.Upload},F=t=>o.createElement(E[t.name],{className:`${s.prefix}-icon`}),v=t=>{const{customIcon:u}=o.useContext(S.EditorContext),c=u[t.name];if(typeof c=="object"){const r=c.component;return typeof r=="function"?n.jsx(r,{...c.props}):n.jsx("span",{dangerouslySetInnerHTML:{__html:c.component}})}return n.jsx(F,{name:t.name})},L=`${s.prefix}-modal-container`,p=t=>{const{theme:u,rootRef:c}=o.useContext(S.EditorContext),{onClose:r=()=>{},onAdjust:C=()=>{},style:I={},showMask:w=!0}=t,[m,j]=o.useState(t.visible),[z,y]=o.useState([`${s.prefix}-modal`]),f=o.useRef(null),k=o.useRef(null),a=o.useRef(),N=o.useRef(null),[x,d]=o.useState({maskStyle:{zIndex:-1},modalStyle:{zIndex:-1},initPos:{left:"0px",top:"0px"},historyPos:{left:"0px",top:"0px"}}),M=o.useMemo(()=>t.isFullscreen?{width:"100%",height:"100%"}:{width:t.width,height:t.height},[t.height,t.isFullscreen,t.width]);return o.useEffect(()=>{var l;const i=(l=c.current)==null?void 0:l.getRootNode();return a.current=i instanceof Document?document.body:i,()=>{a.current=void 0}},[c]),o.useEffect(()=>{let i=()=>{};return!t.isFullscreen&&t.visible&&(i=q.keyMove(k.current,(l,h)=>{d(g=>({...g,initPos:{left:l+"px",top:h+"px"}}))})),i},[t.isFullscreen,t.visible]),o.useEffect(()=>{if(m){const i=f.current.offsetWidth/2,l=f.current.offsetHeight/2,h=document.documentElement.clientWidth/2,g=document.documentElement.clientHeight/2;d(P=>({...P,maskStyle:{zIndex:s.globalConfig.editorConfig.zIndex+b.getZIndexIncrement()},modalStyle:{zIndex:s.globalConfig.editorConfig.zIndex+b.getZIndexIncrement()},initPos:{left:h-i+"px",top:g-l+"px"}}))}},[m]),o.useEffect(()=>{const i=t.visible;i?(y(()=>[`${s.prefix}-modal`,"zoom-in"]),j(i)):(y(()=>[`${s.prefix}-modal`,"zoom-out"]),setTimeout(()=>{j(i)},150))},[t.visible]),n.jsx(n.Fragment,{children:a.current&&R.createPortal(n.jsx("div",{ref:N,className:L,"data-theme":u,children:n.jsxs("div",{className:t.className,style:{...I,display:m?"block":"none"},children:[w&&n.jsx("div",{className:`${s.prefix}-modal-mask`,style:x.maskStyle,onClick:r}),n.jsxs("div",{className:z.join(" "),style:{...x.modalStyle,...x.initPos,...M},ref:f,children:[n.jsx("div",{className:`${s.prefix}-modal-header`,ref:k,children:t.title||""}),n.jsxs("div",{className:`${s.prefix}-modal-func`,children:[t.showAdjust&&n.jsx("div",{className:`${s.prefix}-modal-adjust`,onClick:i=>{i.stopPropagation(),t.isFullscreen?d(l=>({...l,initPos:l.historyPos})):d(l=>({...l,historyPos:l.initPos,initPos:{left:"0",top:"0"}})),C instanceof Function&&C(!t.isFullscreen)},children:n.jsx(v,{name:t.isFullscreen?"minimize":"maximize"})}),n.jsx("div",{className:`${s.prefix}-modal-close`,onClick:i=>{i.stopPropagation(),t.onClose&&t.onClose()},children:n.jsx(v,{name:"close"})})]}),n.jsx("div",{className:`${s.prefix}-modal-body`,children:t.children})]})]})}),a.current)})};exports.IconIns=v;exports.Modal=p;