wysimark-lite 0.27.9 → 0.27.10
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.js +1 -1
- package/dist/index.mjs +13 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1725,4 +1725,4 @@ ${At(r.slice(1),o).trimStart()}`:At(r,o)).split(`
|
|
|
1725
1725
|
margin-top: 0.5em;
|
|
1726
1726
|
color: var(--shade-500);
|
|
1727
1727
|
line-height: 1.375;
|
|
1728
|
-
`;import{Fragment as Hk,jsx as G,jsxs as Ct}from"react/jsx-runtime";var Nk=Sk("enter");function Cd({dest:e,close:t}){let o=zk(),r=Rk(null),[n,i]=Ye({x:0,y:0}),a=Jt((v,$)=>{i(de=>({x:de.x+v,y:de.y+$}))},[]),l=oe({src:r,dest:e},({src:v,dest:$},de)=>!v||!$?{left:0,top:0}:Be(v,de,{left:$.left-12,top:$.top+$.height},{margin:16})),s={...l,left:l.left+n.x,top:l.top+n.y},m=Lk(()=>{let{selection:v}=o;return v&&!$k.isCollapsed(v)?Bk.string(o,v):""},[]),[c,d]=Ye(""),[p,u]=Ye(""),[h,k]=Ye(m),[L,M]=Ye(m),[T,D]=Ye("external"),[P,H]=Ye(!1),C=()=>{if(T==="internal"){let v=p.trim();if(v==="")return;let $=h.trim(),de=$&&$!==me(v)?`${v}|${$}`:v;o.anchor.insertLink(Ce(de),$||me(v),{select:!0})}else{let v=h.trim()||c,$=L.trim()||void 0;o.anchor.insertLink(c,v,{select:!0,title:$})}Dk.focus(o),t()},B=Jt(v=>{d(v.currentTarget.value)},[d]),S=Jt(v=>{let $=ao(v.currentTarget.value);u($.target),$.display!==void 0&&k($.display)},[u,k]),R=Jt(v=>{let $=v.currentTarget.value;k($),P||M($)},[k,M,P]),w=Jt(v=>{M(v.currentTarget.value),H(!0)},[M]),U=v=>{Nk(v)&&(v.preventDefault(),v.stopPropagation(),C())};return Ct(Hk,{children:[G(Re,{close:t}),Ct(Qa,{ref:r,style:s,children:[G(De,{onDrag:a}),Ct("div",{style:{padding:"0.75em"},children:[o.wysimark.enableInternalLinks?G(Vt,{children:Ct("div",{style:{display:"flex",gap:"0.25em",padding:"0.25em",borderRadius:"0.375em",background:"var(--shade-100)",width:"100%"},children:[G("button",{type:"button",onClick:()=>D("external"),style:{flex:"1 1 0",border:0,borderRadius:"0.25em",padding:"0.375em 0.5em",cursor:"pointer",background:T==="external"?"white":"transparent",color:T==="external"?"var(--shade-700)":"var(--shade-500)",boxShadow:T==="external"?"0 1px 2px rgb(0 0 0 / 12%)":"none"},children:f("linkTypeExternal")}),G("button",{type:"button",onClick:()=>D("internal"),style:{flex:"1 1 0",border:0,borderRadius:"0.25em",padding:"0.375em 0.5em",cursor:"pointer",background:T==="internal"?"white":"transparent",color:T==="internal"?"var(--shade-700)":"var(--shade-500)",boxShadow:T==="internal"?"0 1px 2px rgb(0 0 0 / 12%)":"none"},children:f("linkTypeInternal")})]})}):null,G(Vt,{style:{marginTop:o.wysimark.enableInternalLinks?"0.5em":0},children:T==="internal"?G(_t,{type:"text",value:p,autoFocus:!0,placeholder:f("internalLinkTarget"),onChange:S,onKeyDown:U}):G(_t,{type:"text",value:c,autoFocus:!0,placeholder:f("linkUrl"),onChange:B,onKeyDown:U})}),G(Vt,{style:{marginTop:"0.5em"},children:G(_t,{type:"text",value:h,placeholder:f("linkText"),onChange:R,onKeyDown:U})}),Ct(Vt,{style:{marginTop:"0.5em"},children:[T==="external"?G(_t,{type:"text",value:L,placeholder:f("tooltipText"),onChange:w,onKeyDown:U}):G("span",{style:{flex:"1 1 auto"}}),Ct(vn,{onClick:C,children:[G(tr,{}),G(ed,{})]}),G(vn,{onClick:t,style:{marginLeft:"0.25em",background:"var(--shade-400)"},children:G(Ed,{})})]}),T==="external"?G(Tn,{children:f("tooltipHint")}):G(Tn,{children:f("internalLinkTargetHint")})]})]})]})}var wn=[{icon:tr,title:f("insertLink"),more:!0,hotkey:"mod+k",Component:Cd},{icon:pd,title:f("insertImageFromUrl"),more:!0,Component:Id},{icon:sd,title:f("insertTable"),more:!0,Component:Yp},{icon:xd,title:f("horizontalRule"),hotkey:"super+-",action:e=>e.horizontalRule.insertHorizontalRule()}],Pd=wn,Sd=wn,Ld=[{icon:dd,title:f("insert"),more:!0,children:wn}];import{Editor as Ak}from"slate";function Pt(e){let t=Ak.marks(e);return{bold:t?.bold||!1,italic:t?.italic||!1,strike:t?.strike||!1,code:t?.code||!1,underline:t?.underline||!1,highlight:t?.highlight||!1}}var Rd=[{icon:gn,title:f("bold"),hotkey:"mod+b",action:e=>e.marksPlugin.toggleBold(),active:e=>Pt(e).bold},{icon:id,title:f("italic"),hotkey:"mod+i",action:e=>e.marksPlugin.toggleItalic(),active:e=>Pt(e).italic},{icon:ud,title:f("strike"),hotkey:"super+k",action:e=>e.marksPlugin.toggleStrike(),active:e=>Pt(e).strike},{icon:md,title:f("inlineCode"),hotkey:"mod+j",action:e=>e.inlineCode.toggleInlineCode(),active:e=>Pt(e).code},{icon:fd,title:f("underline"),hotkey:"mod+u",action:e=>e.marksPlugin.toggleUnderline(),active:e=>Pt(e).underline},{icon:kd,title:f("highlight"),hotkey:"mod+h",action:e=>e.marksPlugin.toggleHighlight(),active:e=>Pt(e).highlight,show:e=>!e.wysimark.disableHighlight}],In=Rd,Bd=[{icon:gn,title:f("format"),more:!0,children:Rd}];var Ok=["unordered-list-item","ordered-list-item","task-list-item"],$d=[{icon:ld,title:f("bulletList"),hotkey:"super+8",action:e=>e.list.convertUnorderedList(!0),active:e=>!!b(e,"unordered-list-item")},{icon:En,title:f("numberedList"),hotkey:"super+7",action:e=>e.list.convertOrderedList(!0),active:e=>!!b(e,"ordered-list-item")},{icon:hd,title:f("checkList"),hotkey:"super+9",action:e=>e.list.convertTaskList(!0),active:e=>!!b(e,"task-list-item"),show:e=>!e.wysimark.disableTaskList}],Mn=[...$d,"divider",...kn],Dd=[{icon:En,title:f("list"),more:!0,active:e=>!!b(e,Ok),children:[...$d,"divider",...kn]}];import{Editor as zd,Path as Uk,Transforms as or}from"slate";var Nd=[{icon:bn,title:f("quote"),hotkey:"super+.",action:e=>{e.blockQuotePlugin.isActive()?e.blockQuotePlugin.outdent():e.blockQuotePlugin.indent()},active:e=>e.blockQuotePlugin.isActive()},{icon:ad,title:f("increaseQuoteDepth"),action:e=>e.blockQuotePlugin.increaseDepth(),active:e=>e.blockQuotePlugin.canIncreaseDepth()},{icon:cd,title:f("codeBlock"),action:e=>{let{selection:t}=e,o=b(e,"code-block");if(o){let[,r]=o,n=zd.string(e,r);or.removeNodes(e,{at:r}),or.insertNodes(e,{type:"paragraph",children:[{text:n}]},{at:r});return}if(t&&!Uk.equals(t.anchor.path,t.focus.path)){e.codeBlock.createCodeBlock({language:"text"});return}if(t&&t.anchor.offset!==t.focus.offset){let r=zd.string(e,t);or.delete(e),or.insertNodes(e,{type:"code-block",language:"text",children:[{type:"code-block-line",children:[{text:r}]}]});return}e.codeBlock.createCodeBlock({language:"text"})},active:e=>!!b(e,"code-block"),show:e=>!e.wysimark.disableCodeBlock}],Cn=Nd,Hd=[{icon:bn,title:f("quote"),more:!0,children:Nd}];var Fk=[...vd,"divider",...Mn,"divider",...In,"divider",...Pd,"divider",...Cn],Wk=[...xn,"divider",...Mn,"divider",...In,"divider",...Sd,"divider",...Cn],Ad=[...xn,"divider",...Dd,"divider",...Bd,"divider",...Ld,"divider",...Hd],Od=Ad;var St=[Fk,Wk,Ad];import{clsx as Vk}from"clsx";import{useCallback as Pn,useRef as _k}from"react";import{ReactEditor as Kk,useSlate as Gk,useSlateStatic as qk}from"slate-react";import{jsx as rr,jsxs as Qk}from"react/jsx-runtime";function Ud({item:e}){let t=qk(),o=Gk(),r=e.active?e.active(o):!1,n=_k(null),i=ne({title:e.title,hotkey:()=>e.hotkey?wo(e.hotkey):void 0}),a=W("menu"),l=Pn(()=>{let c=n.current,d=e.children,p=e.Component;c&&(d?a.open(()=>rr(ct,{dest:c,items:d,close:a.close})):p&&a.open(()=>rr(p,{dest:c,close:a.close})))},[e]),s=Pn(()=>{if(e.action){e.action(t),Kk.focus(t);return}a.layer?a.close():l()},[a.layer,e]),m=Pn(c=>{i.onMouseEnter(c),a.layer&&l()},[a.layer,l,i.onMouseEnter]);return Qk(al,{"data-item-type":"button",ref:n,onMouseEnter:m,onMouseLeave:i.onMouseLeave,onClick:s,className:Vk({"--active":r&&!Er(e?.title)?.includes("Depth"),"--more":e.more,"--disabled":!r&&Er(e?.title)?.includes("Depth")}),children:[rr(e.icon,{}),e.more?rr(Zp,{}):null]})}import{jsx as Lt}from"react/jsx-runtime";function Zk({item:e}){let t=Jk();return e==="divider"?Lt(nl,{"data-item-type":"divider",children:Lt(il,{})}):(e.show===void 0?!0:e.show(t))?Lt(Ud,{item:e}):null}function ex(e){let t=e.querySelector("[data-item-type=button]"),o=e.querySelector("[data-item-type=divider]");return!t||!o?null:{toolbar:e.offsetWidth,button:t.offsetWidth,divider:o.offsetWidth}}function tx(e,t,o){let r=0;for(let n of e)r+=n==="divider"?o:t;return r}var ox=4;function Fd(){let e=Xk(null),[t,o]=Yk(Od);return jk(()=>{let r=e.current;if(!r)return;let n=()=>{let a=ex(r);if(a){for(let l=0;l<St.length-1;l++)if(tx(St[l],a.button,a.divider)<a.toolbar-ox){o(St[l]);return}o(St[St.length-1])}},i=new ResizeObserver(n);return i.observe(r),()=>{i.disconnect()}},[]),Lt(ol,{ref:e,children:Lt(rl,{children:t.map((r,n)=>Lt(Zk,{item:r},typeof r=="string"?n:r.title))})})}import{jsx as Sn,jsxs as px}from"react/jsx-runtime";function Wd({attributes:e,Editable:t}){let o=ix(null),r=cx(),n=mx(),i=nx(a=>{a.target===a.currentTarget&&(lx.select(r,ax.end(r,[])),sx.focus(r))},[r]);return Sn(Fa,{children:px(Ja,{ref:o,className:rx({"--focused":n}),style:{height:r.toolbar.height,minHeight:r.toolbar.minHeight,maxHeight:r.toolbar.maxHeight},onClick:i,children:[Sn(Fd,{}),Sn(t,{as:Ya,...e,style:{overflowY:"auto"}})]})})}var Vd=y((e,t)=>(e.toolbar={height:t.toolbar?.height,minHeight:t.toolbar?.minHeight,maxHeight:t.toolbar?.maxHeight,showUploadButtons:t.toolbar?.showUploadButtons??!0},{name:"toolbar",editor:{},renderEditable:Wd,editableProps:{}}));import{Editor as Ln,Node as dx,Path as ux,Transforms as fx}from"slate";var _d=y(e=>(e.allowTrailingBlock=!0,{name:"trailing-block",editor:{normalizeNode:t=>{if(!Ln.isEditor(t[0]))return!1;let o=[e.children.length-1],r=dx.child(e,e.children.length-1);return(Ln.hasBlocks(e,r)||Ln.isVoid(e,r))&&fx.insertNodes(e,{type:"paragraph",children:[{text:""}]},{at:ux.next(o)}),!0}}}));import{Transforms as hx}from"slate";function gx(e,t){let o=Pe(t),r=Le(o,{enableInternalLinks:e.wysimark.enableInternalLinks});hx.insertNodes(e,r)}function Kd(e){return{pasteMarkdown:g(gx,e)}}function bx(e){return e.length===1&&e[0]==="text/plain"}function Ex(e){return/^>\s*\[![A-Za-z0-9_-]+\][+-]?(?:\s|$)/m.test(e)}var Gd=y(e=>(e.pasteMarkdown=Kd(e),{name:"paste-markdown",editor:{},editableProps:{onPaste(t){let o=Array.from(t.clipboardData.types),r=t.clipboardData.getData("text/markdown"),n=t.clipboardData.getData("text/plain");return r||n&&(bx(o)||Ex(n))?(e.pasteMarkdown.pasteMarkdown(r||n),Ue(t),!0):!1}}}));import{jsx as xx}from"react/jsx-runtime";function kx(e){let t={...e.attributes,style:{...e.attributes.style,width:void 0,maxWidth:void 0}};return xx("span",{...t,children:e.children})}var qd=y((e,t,{createPolicy:o})=>(e.placeholder={},o({name:"placeholder",editableProps:{renderPlaceholder:kx}})));var Qd=[Gd,Fm,Ml,Ym,Oc,lc,As,xm,Mm,Wp,rc,_d,Dc,Ll,Wc,Dm,Kp,Vd,Is,qd];var yx=na(Qd),{withSink:jd,SinkEditable:Xd}=yx;import{useState as vx}from"react";import{createEditor as Tx,Editor as wx,Transforms as Ix}from"slate";import{withHistory as Mx}from"slate-history";import{withReact as Cx}from"slate-react";function Rn({authToken:e,height:t,minHeight:o,maxHeight:r,disableRawMode:n,disableTaskList:i,disableCodeBlock:a,disableHighlight:l,enableInternalLinks:s,renderInternalLinkPreview:m,renderInternalEmbed:c,onInternalLinkClick:d}={}){let[p]=vx(()=>{let u=Tx(),h=jd(Cx(Mx(u)),{toolbar:{height:t,minHeight:o,maxHeight:r,showUploadButtons:!!e},image:{}});return h.convertElement.addConvertElementType("paragraph"),u.wysimark={disableRawMode:n??!0,disableTaskList:i,disableCodeBlock:a,disableHighlight:l??!0,enableInternalLinks:s??!1,renderInternalLinkPreview:m,renderInternalEmbed:c,onInternalLinkClick:d},u.getMarkdown=()=>fe(u.children,{enableInternalLinks:u.wysimark.enableInternalLinks}),u.setMarkdown=k=>{let L=Pe(k),M=Le(L,{enableInternalLinks:u.wysimark.enableInternalLinks});u.children=M,u.selection=null,Ix.select(u,wx.start(u,[0]))},h});return p.wysimark.renderInternalLinkPreview=m,p.wysimark.renderInternalEmbed=c,p.wysimark.onInternalLinkClick=d,p}import{jsx as le,jsxs as Jd}from"react/jsx-runtime";function $x({children:e,attributes:t}){return le("span",{...t,children:e})}function Zd({editor:e,value:t,onChange:o,throttleInMs:r=1e3,placeholder:n,className:i,style:a,onImageChange:l,onFileSelect:s}){let[m,c]=Yd(!1),[d,p]=Yd(t),u=eo(!1),h=eo(void 0),k=eo(void 0),L=eo(null),M=eo(o);M.current=o;let T=Zt(Px(()=>{let w=fe(e.children,{enableInternalLinks:e.wysimark.enableInternalLinks});e.wysimark.prevValue={markdown:w,children:e.children},M.current(w)},r,{leading:!1,trailing:!0}),[e,r]),D=Zt(()=>{k.current!==e.children&&(k.current=e.children,T())},[T]);if(!m){let w=L.current??t;if(L.current!==null&&(L.current=null),e.wysimark.prevValue==null||h.current==null){u.current=!0;let U=Pe(w),v=Le(U,{enableInternalLinks:e.wysimark.enableInternalLinks});e.children=v,k.current=h.current=v,e.wysimark.prevValue={markdown:w,children:v}}else if(w!==e.wysimark.prevValue.markdown){u.current=!0;let U=Pe(w),v=Le(U,{enableInternalLinks:e.wysimark.enableInternalLinks});e.children=v,e.selection=null,Lx.select(e,Sx.start(e,[0]))}}let P=Zt(()=>{navigator.userAgent.toLowerCase().includes("firefox")&&Rx.focus(e)},[e]),H=Zt(()=>{T.flush()},[T]),C=w=>{let U=w.target.value;p(U),o(U)},B=Zt(()=>{let w=e.getMarkdown();p(w)},[e]),S=()=>{m?(L.current=d,e.wysimark.prevValue=void 0,h.current=void 0,k.current=void 0):B(),c(!m)};e.wysimark.onImageChange=l,e.wysimark.onFileSelect=s;let R=e.wysimark.disableRawMode;return Jd("div",{style:{position:"relative",display:"flex",flexDirection:"column",flex:1,minHeight:0},children:[!R&&le("div",{style:{position:"absolute",top:"5px",right:"25px",zIndex:10},children:le("div",{onClick:S,style:{background:"none",border:m?"1px solid #4a90e2":"1px solid transparent",cursor:"pointer",padding:"6px",borderRadius:"4px",backgroundColor:m?"rgba(74, 144, 226, 0.1)":"transparent",boxShadow:m?"0 1px 3px rgba(0, 0, 0, 0.1)":"none",transition:"all 0.2s ease-in-out",display:"flex",alignItems:"center",justifyContent:"center"},title:m?f("switchToVisualEditor"):f("switchToRawMarkdown"),role:"button",tabIndex:0,onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(S(),w.preventDefault())},children:Jd("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[le("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:m?"#4a90e2":"currentColor",strokeWidth:"1.5",fill:m?"rgba(74, 144, 226, 0.05)":"transparent"}),le("path",{d:"M7 15V9L10 12L13 9V15",stroke:m?"#4a90e2":"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),le("path",{d:"M16 9H18V15",stroke:m?"#4a90e2":"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),le("path",{d:"M16 12H18",stroke:m?"#4a90e2":"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})})}),le("div",{style:{display:m?"block":"none",textAlign:"center"},children:le("textarea",{value:Dt(d),onChange:C,placeholder:n,className:i,style:{width:"calc(100% - 60px)",margin:"0 auto",minHeight:"200px",padding:"20px",fontFamily:"monospace",fontSize:"1rem",color:"#333",lineHeight:"1.5",backgroundColor:"#fff",border:"1px solid #ddd",borderRadius:"4px",...a}})}),le("div",{style:{display:m?"none":"flex",flexDirection:"column",flex:1,minHeight:0},children:le(Bx,{editor:e,initialValue:h.current,onChange:D,children:le(Xd,{renderLeaf:$x,onMouseDown:P,onBlur:H,placeholder:n,className:i,style:a})})})]})}import{jsx as eu}from"react/jsx-runtime";function Ux({standaloneOptions:{onChange:e,placeholder:t,className:o,onImageChange:r,onFileSelect:n,...i},standaloneMethodsRef:a}){let[l,s]=Ax(i.initialMarkdown||""),m=Hx(l),c=Rn(i);m.current=l,Nx(a,()=>({getMarkdown(){return m.current},setMarkdown(p){m.current=p,s(p)}}),[m,s]);let d=zx(p=>{m.current=p,s(p),e?.(p)},[c]);return eu(Zd,{editor:c,value:l,className:o||"",onChange:d,placeholder:t,onImageChange:r,onFileSelect:n})}function i6(e,t){let o=Dx(),r=Ox(e);return r.render(eu(Ux,{standaloneMethodsRef:o,standaloneOptions:t})),{unmount(){try{r.unmount()}catch{}},getMarkdown(){return o.current?.getMarkdown()||""},setMarkdown(n){o.current?.setMarkdown(n)}}}export{Zd as Editable,i6 as createWysimark,lo as unescapeMarkdown,Rn as useEditor};
|
|
1728
|
+
`;import{Fragment as Hk,jsx as G,jsxs as Ct}from"react/jsx-runtime";var Nk=Sk("enter");function Cd({dest:e,close:t}){let o=zk(),r=Rk(null),[n,i]=Ye({x:0,y:0}),a=Jt((v,$)=>{i(de=>({x:de.x+v,y:de.y+$}))},[]),l=oe({src:r,dest:e},({src:v,dest:$},de)=>!v||!$?{left:0,top:0}:Be(v,de,{left:$.left-12,top:$.top+$.height},{margin:16})),s={...l,left:l.left+n.x,top:l.top+n.y},m=Lk(()=>{let{selection:v}=o;return v&&!$k.isCollapsed(v)?Bk.string(o,v):""},[]),[c,d]=Ye(""),[p,u]=Ye(""),[h,k]=Ye(m),[L,M]=Ye(m),[T,D]=Ye("external"),[P,H]=Ye(!1),C=()=>{if(T==="internal"){let v=p.trim();if(v==="")return;let $=h.trim(),de=$&&$!==me(v)?`${v}|${$}`:v;o.anchor.insertLink(Ce(de),$||me(v),{select:!0})}else{let v=h.trim()||c,$=L.trim()||void 0;o.anchor.insertLink(c,v,{select:!0,title:$})}Dk.focus(o),t()},B=Jt(v=>{d(v.currentTarget.value)},[d]),S=Jt(v=>{let $=ao(v.currentTarget.value);u($.target),$.display!==void 0&&k($.display)},[u,k]),R=Jt(v=>{let $=v.currentTarget.value;k($),P||M($)},[k,M,P]),w=Jt(v=>{M(v.currentTarget.value),H(!0)},[M]),U=v=>{Nk(v)&&(v.preventDefault(),v.stopPropagation(),C())};return Ct(Hk,{children:[G(Re,{close:t}),Ct(Qa,{ref:r,style:s,children:[G(De,{onDrag:a}),Ct("div",{style:{padding:"0.75em"},children:[o.wysimark.enableInternalLinks?G(Vt,{children:Ct("div",{style:{display:"flex",gap:"0.25em",padding:"0.25em",borderRadius:"0.375em",background:"var(--shade-100)",width:"100%"},children:[G("button",{type:"button",onClick:()=>D("external"),style:{flex:"1 1 0",border:0,borderRadius:"0.25em",padding:"0.375em 0.5em",cursor:"pointer",background:T==="external"?"white":"transparent",color:T==="external"?"var(--shade-700)":"var(--shade-500)",boxShadow:T==="external"?"0 1px 2px rgb(0 0 0 / 12%)":"none"},children:f("linkTypeExternal")}),G("button",{type:"button",onClick:()=>D("internal"),style:{flex:"1 1 0",border:0,borderRadius:"0.25em",padding:"0.375em 0.5em",cursor:"pointer",background:T==="internal"?"white":"transparent",color:T==="internal"?"var(--shade-700)":"var(--shade-500)",boxShadow:T==="internal"?"0 1px 2px rgb(0 0 0 / 12%)":"none"},children:f("linkTypeInternal")})]})}):null,G(Vt,{style:{marginTop:o.wysimark.enableInternalLinks?"0.5em":0},children:T==="internal"?G(_t,{type:"text",value:p,autoFocus:!0,placeholder:f("internalLinkTarget"),onChange:S,onKeyDown:U}):G(_t,{type:"text",value:c,autoFocus:!0,placeholder:f("linkUrl"),onChange:B,onKeyDown:U})}),G(Vt,{style:{marginTop:"0.5em"},children:G(_t,{type:"text",value:h,placeholder:f("linkText"),onChange:R,onKeyDown:U})}),Ct(Vt,{style:{marginTop:"0.5em"},children:[T==="external"?G(_t,{type:"text",value:L,placeholder:f("tooltipText"),onChange:w,onKeyDown:U}):G("span",{style:{flex:"1 1 auto"}}),Ct(vn,{onClick:C,children:[G(tr,{}),G(ed,{})]}),G(vn,{onClick:t,style:{marginLeft:"0.25em",background:"var(--shade-400)"},children:G(Ed,{})})]}),T==="external"?G(Tn,{children:f("tooltipHint")}):G(Tn,{children:f("internalLinkTargetHint")})]})]})]})}var wn=[{icon:tr,title:f("insertLink"),more:!0,hotkey:"mod+k",Component:Cd},{icon:pd,title:f("insertImageFromUrl"),more:!0,Component:Id},{icon:sd,title:f("insertTable"),more:!0,Component:Yp},{icon:xd,title:f("horizontalRule"),hotkey:"super+-",action:e=>e.horizontalRule.insertHorizontalRule()}],Pd=wn,Sd=wn,Ld=[{icon:dd,title:f("insert"),more:!0,children:wn}];import{Editor as Ak}from"slate";function Pt(e){let t=Ak.marks(e);return{bold:t?.bold||!1,italic:t?.italic||!1,strike:t?.strike||!1,code:t?.code||!1,underline:t?.underline||!1,highlight:t?.highlight||!1}}var Rd=[{icon:gn,title:f("bold"),hotkey:"mod+b",action:e=>e.marksPlugin.toggleBold(),active:e=>Pt(e).bold},{icon:id,title:f("italic"),hotkey:"mod+i",action:e=>e.marksPlugin.toggleItalic(),active:e=>Pt(e).italic},{icon:ud,title:f("strike"),hotkey:"super+k",action:e=>e.marksPlugin.toggleStrike(),active:e=>Pt(e).strike},{icon:md,title:f("inlineCode"),hotkey:"mod+j",action:e=>e.inlineCode.toggleInlineCode(),active:e=>Pt(e).code},{icon:fd,title:f("underline"),hotkey:"mod+u",action:e=>e.marksPlugin.toggleUnderline(),active:e=>Pt(e).underline},{icon:kd,title:f("highlight"),hotkey:"mod+h",action:e=>e.marksPlugin.toggleHighlight(),active:e=>Pt(e).highlight,show:e=>!e.wysimark.disableHighlight}],In=Rd,Bd=[{icon:gn,title:f("format"),more:!0,children:Rd}];var Ok=["unordered-list-item","ordered-list-item","task-list-item"],$d=[{icon:ld,title:f("bulletList"),hotkey:"super+8",action:e=>e.list.convertUnorderedList(!0),active:e=>!!b(e,"unordered-list-item")},{icon:En,title:f("numberedList"),hotkey:"super+7",action:e=>e.list.convertOrderedList(!0),active:e=>!!b(e,"ordered-list-item")},{icon:hd,title:f("checkList"),hotkey:"super+9",action:e=>e.list.convertTaskList(!0),active:e=>!!b(e,"task-list-item"),show:e=>!e.wysimark.disableTaskList}],Mn=[...$d,"divider",...kn],Dd=[{icon:En,title:f("list"),more:!0,active:e=>!!b(e,Ok),children:[...$d,"divider",...kn]}];import{Editor as zd,Path as Uk,Transforms as or}from"slate";var Nd=[{icon:bn,title:f("quote"),hotkey:"super+.",action:e=>{e.blockQuotePlugin.isActive()?e.blockQuotePlugin.outdent():e.blockQuotePlugin.indent()},active:e=>e.blockQuotePlugin.isActive()},{icon:ad,title:f("increaseQuoteDepth"),action:e=>e.blockQuotePlugin.increaseDepth(),active:e=>e.blockQuotePlugin.canIncreaseDepth()},{icon:cd,title:f("codeBlock"),action:e=>{let{selection:t}=e,o=b(e,"code-block");if(o){let[,r]=o,n=zd.string(e,r);or.removeNodes(e,{at:r}),or.insertNodes(e,{type:"paragraph",children:[{text:n}]},{at:r});return}if(t&&!Uk.equals(t.anchor.path,t.focus.path)){e.codeBlock.createCodeBlock({language:"text"});return}if(t&&t.anchor.offset!==t.focus.offset){let r=zd.string(e,t);or.delete(e),or.insertNodes(e,{type:"code-block",language:"text",children:[{type:"code-block-line",children:[{text:r}]}]});return}e.codeBlock.createCodeBlock({language:"text"})},active:e=>!!b(e,"code-block"),show:e=>!e.wysimark.disableCodeBlock}],Cn=Nd,Hd=[{icon:bn,title:f("quote"),more:!0,children:Nd}];var Fk=[...vd,"divider",...Mn,"divider",...In,"divider",...Pd,"divider",...Cn],Wk=[...xn,"divider",...Mn,"divider",...In,"divider",...Sd,"divider",...Cn],Ad=[...xn,"divider",...Dd,"divider",...Bd,"divider",...Ld,"divider",...Hd],Od=Ad;var St=[Fk,Wk,Ad];import{clsx as Vk}from"clsx";import{useCallback as Pn,useRef as _k}from"react";import{ReactEditor as Kk,useSlate as Gk,useSlateStatic as qk}from"slate-react";import{jsx as rr,jsxs as Qk}from"react/jsx-runtime";function Ud({item:e}){let t=qk(),o=Gk(),r=e.active?e.active(o):!1,n=_k(null),i=ne({title:e.title,hotkey:()=>e.hotkey?wo(e.hotkey):void 0}),a=W("menu"),l=Pn(()=>{let c=n.current,d=e.children,p=e.Component;c&&(d?a.open(()=>rr(ct,{dest:c,items:d,close:a.close})):p&&a.open(()=>rr(p,{dest:c,close:a.close})))},[e]),s=Pn(()=>{if(e.action){e.action(t),Kk.focus(t);return}a.layer?a.close():l()},[a.layer,e]),m=Pn(c=>{i.onMouseEnter(c),a.layer&&l()},[a.layer,l,i.onMouseEnter]);return Qk(al,{"data-item-type":"button",ref:n,onMouseEnter:m,onMouseLeave:i.onMouseLeave,onClick:s,className:Vk({"--active":r&&!Er(e?.title)?.includes("Depth"),"--more":e.more,"--disabled":!r&&Er(e?.title)?.includes("Depth")}),children:[rr(e.icon,{}),e.more?rr(Zp,{}):null]})}import{jsx as Lt}from"react/jsx-runtime";function Zk({item:e}){let t=Jk();return e==="divider"?Lt(nl,{"data-item-type":"divider",children:Lt(il,{})}):(e.show===void 0?!0:e.show(t))?Lt(Ud,{item:e}):null}function ex(e){let t=e.querySelector("[data-item-type=button]"),o=e.querySelector("[data-item-type=divider]");return!t||!o?null:{toolbar:e.offsetWidth,button:t.offsetWidth,divider:o.offsetWidth}}function tx(e,t,o){let r=0;for(let n of e)r+=n==="divider"?o:t;return r}var ox=4;function Fd(){let e=Xk(null),[t,o]=Yk(Od);return jk(()=>{let r=e.current;if(!r)return;let n=()=>{let a=ex(r);if(a){for(let l=0;l<St.length-1;l++)if(tx(St[l],a.button,a.divider)<a.toolbar-ox){o(St[l]);return}o(St[St.length-1])}},i=new ResizeObserver(n);return i.observe(r),()=>{i.disconnect()}},[]),Lt(ol,{ref:e,children:Lt(rl,{children:t.map((r,n)=>Lt(Zk,{item:r},typeof r=="string"?n:r.title))})})}import{jsx as Sn,jsxs as px}from"react/jsx-runtime";function Wd({attributes:e,Editable:t}){let o=ix(null),r=cx(),n=mx(),i=nx(a=>{a.target===a.currentTarget&&(lx.select(r,ax.end(r,[])),sx.focus(r))},[r]);return Sn(Fa,{children:px(Ja,{ref:o,className:rx({"--focused":n}),style:{height:r.toolbar.height,minHeight:r.toolbar.minHeight,maxHeight:r.toolbar.maxHeight},onClick:i,children:[Sn(Fd,{}),Sn(t,{as:Ya,...e,style:{overflowY:"auto"}})]})})}var Vd=y((e,t)=>(e.toolbar={height:t.toolbar?.height,minHeight:t.toolbar?.minHeight,maxHeight:t.toolbar?.maxHeight,showUploadButtons:t.toolbar?.showUploadButtons??!0},{name:"toolbar",editor:{},renderEditable:Wd,editableProps:{}}));import{Editor as Ln,Node as dx,Path as ux,Transforms as fx}from"slate";var _d=y(e=>(e.allowTrailingBlock=!0,{name:"trailing-block",editor:{normalizeNode:t=>{if(!Ln.isEditor(t[0]))return!1;let o=[e.children.length-1],r=dx.child(e,e.children.length-1);return(Ln.hasBlocks(e,r)||Ln.isVoid(e,r))&&fx.insertNodes(e,{type:"paragraph",children:[{text:""}]},{at:ux.next(o)}),!0}}}));import{Transforms as hx}from"slate";function gx(e,t){let o=Pe(t),r=Le(o,{enableInternalLinks:e.wysimark.enableInternalLinks});hx.insertNodes(e,r)}function Kd(e){return{pasteMarkdown:g(gx,e)}}function bx(e){return e.length===1&&e[0]==="text/plain"}function Ex(e){return/^>\s*\[![A-Za-z0-9_-]+\][+-]?(?:\s|$)/m.test(e)}var Gd=y(e=>(e.pasteMarkdown=Kd(e),{name:"paste-markdown",editor:{},editableProps:{onPaste(t){let o=Array.from(t.clipboardData.types),r=t.clipboardData.getData("text/markdown"),n=t.clipboardData.getData("text/plain");return r||n&&(bx(o)||Ex(n))?(e.pasteMarkdown.pasteMarkdown(r||n),Ue(t),!0):!1}}}));import{jsx as xx}from"react/jsx-runtime";function kx(e){let t={...e.attributes,style:{...e.attributes.style,width:void 0,maxWidth:void 0}};return xx("span",{...t,children:e.children})}var qd=y((e,t,{createPolicy:o})=>(e.placeholder={},o({name:"placeholder",editableProps:{renderPlaceholder:kx}})));var Qd=[Gd,Fm,Ml,Ym,Oc,lc,As,xm,Mm,Wp,rc,_d,Dc,Ll,Wc,Dm,Kp,Vd,Is,qd];var yx=na(Qd),{withSink:jd,SinkEditable:Xd}=yx;import{useState as vx}from"react";import{createEditor as Tx,Editor as wx,Transforms as Ix}from"slate";import{withHistory as Mx}from"slate-history";import{withReact as Cx}from"slate-react";function Rn({authToken:e,height:t,minHeight:o,maxHeight:r,disableRawMode:n,disableTaskList:i,disableCodeBlock:a,disableHighlight:l,enableInternalLinks:s,renderInternalLinkPreview:m,renderInternalEmbed:c,onInternalLinkClick:d}={}){let[p]=vx(()=>{let u=Tx();u.wysimark={disableRawMode:n??!0,disableTaskList:i,disableCodeBlock:a,disableHighlight:l??!0,enableInternalLinks:s??!1,renderInternalLinkPreview:m,renderInternalEmbed:c,onInternalLinkClick:d};let h=jd(Cx(Mx(u)),{toolbar:{height:t,minHeight:o,maxHeight:r,showUploadButtons:!!e},image:{}});return h.convertElement.addConvertElementType("paragraph"),u.getMarkdown=()=>fe(u.children,{enableInternalLinks:u.wysimark.enableInternalLinks}),u.setMarkdown=k=>{let L=Pe(k),M=Le(L,{enableInternalLinks:u.wysimark.enableInternalLinks});u.children=M,u.selection=null,Ix.select(u,wx.start(u,[0]))},h});return p.wysimark.renderInternalLinkPreview=m,p.wysimark.renderInternalEmbed=c,p.wysimark.onInternalLinkClick=d,p}import{jsx as le,jsxs as Jd}from"react/jsx-runtime";function $x({children:e,attributes:t}){return le("span",{...t,children:e})}function Zd({editor:e,value:t,onChange:o,throttleInMs:r=1e3,placeholder:n,className:i,style:a,onImageChange:l,onFileSelect:s}){let[m,c]=Yd(!1),[d,p]=Yd(t),u=eo(!1),h=eo(void 0),k=eo(void 0),L=eo(null),M=eo(o);M.current=o;let T=Zt(Px(()=>{let w=fe(e.children,{enableInternalLinks:e.wysimark.enableInternalLinks});e.wysimark.prevValue={markdown:w,children:e.children},M.current(w)},r,{leading:!1,trailing:!0}),[e,r]),D=Zt(()=>{k.current!==e.children&&(k.current=e.children,T())},[T]);if(!m){let w=L.current??t;if(L.current!==null&&(L.current=null),e.wysimark.prevValue==null||h.current==null){u.current=!0;let U=Pe(w),v=Le(U,{enableInternalLinks:e.wysimark.enableInternalLinks});e.children=v,k.current=h.current=v,e.wysimark.prevValue={markdown:w,children:v}}else if(w!==e.wysimark.prevValue.markdown){u.current=!0;let U=Pe(w),v=Le(U,{enableInternalLinks:e.wysimark.enableInternalLinks});e.children=v,e.selection=null,Lx.select(e,Sx.start(e,[0]))}}let P=Zt(()=>{navigator.userAgent.toLowerCase().includes("firefox")&&Rx.focus(e)},[e]),H=Zt(()=>{T.flush()},[T]),C=w=>{let U=w.target.value;p(U),o(U)},B=Zt(()=>{let w=e.getMarkdown();p(w)},[e]),S=()=>{m?(L.current=d,e.wysimark.prevValue=void 0,h.current=void 0,k.current=void 0):B(),c(!m)};e.wysimark.onImageChange=l,e.wysimark.onFileSelect=s;let R=e.wysimark.disableRawMode;return Jd("div",{style:{position:"relative",display:"flex",flexDirection:"column",flex:1,minHeight:0},children:[!R&&le("div",{style:{position:"absolute",top:"5px",right:"25px",zIndex:10},children:le("div",{onClick:S,style:{background:"none",border:m?"1px solid #4a90e2":"1px solid transparent",cursor:"pointer",padding:"6px",borderRadius:"4px",backgroundColor:m?"rgba(74, 144, 226, 0.1)":"transparent",boxShadow:m?"0 1px 3px rgba(0, 0, 0, 0.1)":"none",transition:"all 0.2s ease-in-out",display:"flex",alignItems:"center",justifyContent:"center"},title:m?f("switchToVisualEditor"):f("switchToRawMarkdown"),role:"button",tabIndex:0,onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(S(),w.preventDefault())},children:Jd("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[le("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:m?"#4a90e2":"currentColor",strokeWidth:"1.5",fill:m?"rgba(74, 144, 226, 0.05)":"transparent"}),le("path",{d:"M7 15V9L10 12L13 9V15",stroke:m?"#4a90e2":"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),le("path",{d:"M16 9H18V15",stroke:m?"#4a90e2":"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),le("path",{d:"M16 12H18",stroke:m?"#4a90e2":"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})})}),le("div",{style:{display:m?"block":"none",textAlign:"center"},children:le("textarea",{value:Dt(d),onChange:C,placeholder:n,className:i,style:{width:"calc(100% - 60px)",margin:"0 auto",minHeight:"200px",padding:"20px",fontFamily:"monospace",fontSize:"1rem",color:"#333",lineHeight:"1.5",backgroundColor:"#fff",border:"1px solid #ddd",borderRadius:"4px",...a}})}),le("div",{style:{display:m?"none":"flex",flexDirection:"column",flex:1,minHeight:0},children:le(Bx,{editor:e,initialValue:h.current,onChange:D,children:le(Xd,{renderLeaf:$x,onMouseDown:P,onBlur:H,placeholder:n,className:i,style:a})})})]})}import{jsx as eu}from"react/jsx-runtime";function Ux({standaloneOptions:{onChange:e,placeholder:t,className:o,onImageChange:r,onFileSelect:n,...i},standaloneMethodsRef:a}){let[l,s]=Ax(i.initialMarkdown||""),m=Hx(l),c=Rn(i);m.current=l,Nx(a,()=>({getMarkdown(){return m.current},setMarkdown(p){m.current=p,s(p)}}),[m,s]);let d=zx(p=>{m.current=p,s(p),e?.(p)},[c]);return eu(Zd,{editor:c,value:l,className:o||"",onChange:d,placeholder:t,onImageChange:r,onFileSelect:n})}function i6(e,t){let o=Dx(),r=Ox(e);return r.render(eu(Ux,{standaloneMethodsRef:o,standaloneOptions:t})),{unmount(){try{r.unmount()}catch{}},getMarkdown(){return o.current?.getMarkdown()||""},setMarkdown(n){o.current?.setMarkdown(n)}}}export{Zd as Editable,i6 as createWysimark,lo as unescapeMarkdown,Rn as useEditor};
|
package/dist/index.mjs
CHANGED
|
@@ -10883,19 +10883,6 @@ function useEditor({
|
|
|
10883
10883
|
} = {}) {
|
|
10884
10884
|
const [editor] = useState13(() => {
|
|
10885
10885
|
const editor2 = createEditor();
|
|
10886
|
-
const nextEditor = withSink(withReact(withHistory(editor2)), {
|
|
10887
|
-
toolbar: {
|
|
10888
|
-
height,
|
|
10889
|
-
minHeight,
|
|
10890
|
-
maxHeight,
|
|
10891
|
-
/**
|
|
10892
|
-
* If `authToken` is provided then show upload buttons.
|
|
10893
|
-
*/
|
|
10894
|
-
showUploadButtons: !!authToken
|
|
10895
|
-
},
|
|
10896
|
-
image: {}
|
|
10897
|
-
});
|
|
10898
|
-
nextEditor.convertElement.addConvertElementType("paragraph");
|
|
10899
10886
|
editor2.wysimark = {
|
|
10900
10887
|
// Disable raw mode (defaults to true)
|
|
10901
10888
|
disableRawMode: disableRawMode ?? true,
|
|
@@ -10910,6 +10897,19 @@ function useEditor({
|
|
|
10910
10897
|
renderInternalEmbed,
|
|
10911
10898
|
onInternalLinkClick
|
|
10912
10899
|
};
|
|
10900
|
+
const nextEditor = withSink(withReact(withHistory(editor2)), {
|
|
10901
|
+
toolbar: {
|
|
10902
|
+
height,
|
|
10903
|
+
minHeight,
|
|
10904
|
+
maxHeight,
|
|
10905
|
+
/**
|
|
10906
|
+
* If `authToken` is provided then show upload buttons.
|
|
10907
|
+
*/
|
|
10908
|
+
showUploadButtons: !!authToken
|
|
10909
|
+
},
|
|
10910
|
+
image: {}
|
|
10911
|
+
});
|
|
10912
|
+
nextEditor.convertElement.addConvertElementType("paragraph");
|
|
10913
10913
|
editor2.getMarkdown = () => {
|
|
10914
10914
|
return serialize(editor2.children, {
|
|
10915
10915
|
enableInternalLinks: editor2.wysimark.enableInternalLinks
|